<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>类别列表</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body style="text-align:center">
	<h2>类别列表</h2>
	<a href="category/add">添加类别</a>
	<table align='center' border='1' cellspacing='0'>
    <tr>
        <td>编号</td>
        <td>类别</td>
        <td>编辑</td>
        <td>删除</td>
    </tr>
    <c:forEach items="${list}" var="a">
        <tr>
            <td>${a.id}</td>
            <td>${a.name}</td>
            <td><button type="button" onclick="location='category/${a.id}'">修改</button></td>
            <td><button type="button" class="delete" url="category/${a.id}">删除</button></td>
        </tr>
    </c:forEach>
	</table>
	<div style="text-align:center">
		<a href="?start=0">首　页</a>
		<c:if test="${page.start != 0}">
			<a href="?start=${page.start-page.count}">上一页</a>
		</c:if>
		<c:if test="${page.start !=  page.last}">
			<a href="?start=${page.start+page.count}">下一页</a>
		</c:if>
		<a href="?start=${page.last}">末　页</a>
	</div>
	<form id="formdelete" method="POST">
		<input type="hidden" name="_method" value="DELETE" />
	</form>
	<script type="text/javascript">
		/* 将post method 改变为delete */
		$(function(){
			$(".delete").click(function(){
				if(confirm("你确定要删除这个类别吗？")){
					var href=$(this).attr("url");
					$("#formdelete").attr("action",href).submit();
				}
				return false;
			})
		})
	</script>
</body>
</html>